<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\controllers;

use Yii;
use \yiike\user\models\Token;
use yii\web\HttpException;
/**
 * Description of LoginController
 *
 * @author Administrator
 */
class LoginController extends \yii\web\Controller{
    
    public function actionIndex($token, $redirect='/') {
        
        $tokenModel = Token::findOne(['code' => $token, 'type' => Token::TYPE_LOGIN]);
        if ($tokenModel && ($user = $tokenModel->user)) {
            Yii::$app->user->login($user);
            $this->redirect($redirect);
        } else {
            throw new HttpException(400, '网址不正确，请能过QQ机器人重新获取');
        }
    }
}
